<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      class User {
        //private只能在User类中使用
        //不修饰的时候  实例化的时候直接添加到了实例对象身上
        // 静态方法和静态属性  只能在 User.name  和 User.show直接调用 static 修饰的时候，直接添加到了User类上面
        #host = 'https://houdunren.com';
        constructor(name) {
          this.name = name;
          this.#check(name);
        }
        set host(url) {
          if (!/^https?:/i.test(url)) {
            throw new Error('非常网址');
          }
          this.#host = url;
        }
        get host() {
          return this.#host;
        }
        #check = () => {
          if (this.name.length <= 5) {
            throw new Error('用户名长度不能小于五位');
          }
          return true;
        };
      }
      console.dir(User);
      let hd = new User('后盾人在线教程');
      // console.log(hd.#host);
      hd.host = 'https://www.hdcms.com';
      console.log(hd.host);
    </script>
  </body>
</html>
